var test = 2

$(function () {
  $('#menubtn').click(function(){
    $("#navBar").css({
      backgroundColor:"white",
    })
  })
})

function mHttp() {
  var m_name = $('#m_name').val()
  var m_datetime = $('#m_datetime').val()
  var intelligent = $('#intelligent').val()
  var m_platform = $('#m_platform').val()
  var m_link = $('#m_link').val()
  var m_cost = $('#m_cost').val()
  var m_project = $('#m_project').val()
  // var m_vouchar = $('#m_vouchar').val()
  
  var files = $("#m_vouchar")[0].files[0];
  if (files.length <= 0) {
      return alert("请选择上传的文件");
  }
  var m_vouchar = new FormData();
  m_vouchar.append("m_vouchar", files[0]);
  
  // var fileM = document.querySelector("#m_vouchar");
  // var fileObj = fileM.files[0];
  // var m_vouchar = new FormData();
  // m_vouchar.append('file', fileObj);

  // let m_vouchar = document.getElementById('m_vouchar').files[0]
  var url1 =  host + '/upload1'
  var url =  host + '/mediumexecute?m_name=' + m_name+ '&m_datetime=' + m_datetime + '&intelligent=' + intelligent + '&m_platform=' + m_platform + '&m_link=' + m_link  + '&m_cost=' + m_cost + '&m_project=' + m_project 
  let httpRequest = new XMLHttpRequest();//第一步：创建需要的对象
  let httpRequest1 = new XMLHttpRequest();//第一步：创建需要的对象
  httpRequest.open('POST', url, true); //第二步：打开连接/***发送json格式文件必须设置请求头 ；如下 - */
  httpRequest1.open('POST', url1, true); //第二步：打开连接/***发送json格式文件必须设置请求头 ；如下 - */
  // httpRequest.open('GET', url, true); //第二步：打开连接/***发送json格式文件必须设置请求头 ；如下 - */
  httpRequest.setRequestHeader("Access-Control-Allow-Credentials", true);//设置请求头 注：post方式必须设置请求头（在建立连接后设置请求头）var obj = { name: 'zhansgan', age: 18 };
  httpRequest.setRequestHeader("Access-Control-Allow-Origin", "*");
  httpRequest1.setRequestHeader("Access-Control-Allow-Credentials", true);//设置请求头 注：post方式必须设置请求头（在建立连接后设置请求头）var obj = { name: 'zhansgan', age: 18 };
  httpRequest1.setRequestHeader("Access-Control-Allow-Origin", "*");
  httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  httpRequest1.setRequestHeader("Content-Type", "multipart/form-data");
  // xhr.setRequestHeader("Content-Type", "text/plain");
  var data = 'm_name=' + m_name+ '&m_datetime=' + m_datetime + '&intelligent=' + intelligent + '&m_platform=' + m_platform + '&m_link=' + m_link  + '&m_cost=' + m_cost + '&m_project=' + m_project 
  httpRequest.send(data);//发送请求 将json写入send中
  httpRequest1.send(m_vouchar);//发送请求 将json写入send中
  /**
   * 获取数据后的处理程序
   */
  httpRequest.onreadystatechange = function () {//请求后的回调接口，可将请求成功后要执行的程序写在其中
    if (httpRequest.readyState == 4 && httpRequest.status == 200) {//验证请求是否发送成功
      var json = JSON.parse(httpRequest.responseText);//获取到服务端返回的数据
      console.log(json);
      if(json['message'] == '提交成功'){
        alert('提交成功！')
      }else{
        alert('提交失败！')
      }
    }
  };
}